webix.ready(function(){
  var URL="";
  var my_template={
      template: "<span style='font-size:20px; font-weight:bold; color:#3498DB'; >领用回收记录</span>&nbsp;/&nbsp;&nbsp;UseRecord <input type='button' value=' 导 出 ' onclick='exportExcel()' style='background: #268fd5;background: 1px solid #268fd5;color: #fff;'>",
      height:45,
      borderless:true 
  };
  var my_toolbar={
      view:"toolbar",
      elements:[           
        {
          view:"datepicker",
          id:"start_date",
          timepicker:true,
          label:"开始",
          labelAlign:"right", 
          name:"start_date",
          stringResult:true,
          format:"%Y-%m-%d",
          width:320
        },
        {
          view:"datepicker",
          id:"end_date",
          timepicker:true,
          label:"结束",
          labelAlign:"right", 
          name:"end_date",
          stringResult:true,
          format:"%Y-%n-%d",
          width:320
        },{
        	   view:"text",
        	   placeholder:"请输入查询条件",
               id:"real_name",
               label:"姓名查询",
               labelAlign:"right", 
               name:"real_name",
               stringResult:true,
               width:320
        },
        {view:"button",value:"查询",width:50,click:check,css:"check"}
      ]   
  };
  var my_datatable={
      view:"datatable",
      id:"mydatatable",     
      columns:[

        {id:"operator_id",header:["ID"],fillspace:true},
        {id:"real_name",header:["操作员",{content:"textFilter",placeholder:"请输入操作员名称进行查询"}],fillspace:true},
        {id:"useNum",header:"领用数量",fillspace:true},
        {id:"recNum",header:"回收数量",fillspace:true},
        {id:"holdNum",header:"持有数量",math:"[$r,:2] - [$r,:3]",fillspace:true},

        {id:"cz",header:"操作",template:"<a class='btn1' href='javascript:void(0);' onclick=\"details('#operator_id#')\">查看刀具统计</a>"+"&nbsp;<a class='btn1' href='javascript:void(0);' onclick=\"details2('#operator_id#')\">查看刀具详情</a>",fillspace:true},    
      ],  
      tooltip:true,
      height:680,     
      select:true,
      math:true,
      editable:true,
      checkboxRefresh:true,
  };
  var page={
		    view:"pager",
		    id:"pagerA",
		   //新用户刚开始没有产生数据出现分页标签
		   // count:1000,
			//master:false,
			//group:15,
			//size:5,
			//page:1,
		    template:"{common.first()}{common.prev()}{common.pages()}{common.next()}{common.last()}",
		    css:"pager",
		    on: {
		      onItemClick: function(id, e, node){
		        if (id == "next") {
		          if($$("pagerA").config.limit==$$("pagerA").config.page+1)
		            {
		              id = $$("pagerA").config.limit-1;
		            }
		          else
		          {
		            id=$$("pagerA").config.page+1;
		          }
		        }
		        else if(id=="prev")
		        {
		          id=$$("pagerA").config.page-1; 
		        }
		        else if(id=="first")
		        {
		          id=0;
		        }
		        else if(id=="last")
		        {
		          id=$$("pagerA").config.limit-1;
		        } 
		        var params={};
		        params.currPage =parseInt(id)+1;
		        params.pageSize =20;
		        params.start_date = $("#startDateHidden").val();
		        params.end_date = $("#endDateHidden").val();
		        postData("getCutterUseList", params,callback);
		      }
		    },
		    height:38,
		    css:{"text-align": "center","margin-top":"20px!important"}
		  };
var params={};
params.pageSize =20;
postData("getCutterUseList", params,callback);
var web={
    container:"body",
    type:"line",
    id:"mylayout",
    rows:[
      my_template,
      my_toolbar,
      my_datatable,
      page
    ],
};

webix.ui(web);//---webix.ui结束----  
function callback(data){
  var text1=JSON.parse(data); 
  var conditions = text1.data.conditions;
  if(conditions.hasOwnProperty("start_date")){
	  $("#startDateHidden").val(conditions.start_date); 
  }
  if(conditions.hasOwnProperty("end_date")){
	  $("#endDateHidden").val(conditions.end_date); 
  }
 // var data = new webix.DataCollection({data:text1.page});
 // $$('mydatatable').data.sync(data);
  $$("mydatatable").clearAll();
  $$("mydatatable").define("data",text1.data.page);
  $$('mydatatable').refresh();
  $$("pagerA").define("limit",text1.data.totalPageCount);
  $$("pagerA").define("count",text1.data.totalCount);
  $$("pagerA").define("size",text1.data.pageSize);
  $$("pagerA").define("page",text1.data.currPage-1);
  $$('pagerA').refresh();
}
function check(){
	  var params = {};
  var startDate=$$("start_date").getValue();
  var endDate=$$("end_date").getValue();
  var real_name=$$("real_name").getValue();
  $("#startDateHidden").val(startDate); 
  $("#endDateHidden").val(endDate); 
  params.currPage = 1;
  params.pageSize = 20;
  params.start_date = startDate;
  params.end_date = endDate;
  params.real_name = real_name;
  postData("getCutterUseList", params,callback);
} 
 
});  
function details(operator_id){
	  var startDate=$("#startDateHidden").val();
	  var endDate=$("#endDateHidden").val();
	  location.href="getCutterUseListByOperatorId?operator_id="+operator_id+"&start_date="+startDate+"&end_date="+endDate;
}


function details2(operator_id){
	  var startDate=$("#startDateHidden").val();
	  var endDate=$("#endDateHidden").val();
	  location.href="operatorDetailUseCutterIndex?operator_id="+operator_id+"&start_date="+startDate+"&end_date="+endDate;
}

  
